<?php
namespace app\index\controller\admin;

use app\common\controller\Back;

class Notice extends Back
{
    protected function initialize()
    {
        parent::initialize();
    }
    
    public function index()
    {
        $form = dcFormCreate([
            'name'         => 'indexAdminNotice',
            'action'       => dcUrl('index/admin.notice/update'),
            'items'        => $this->formItems(config('index.')),
            'reset'        => '重置',
            'class_button' => 'text-left',
        ]);

        $this->assign('form',$form);

        $this->assign($this->site);

        return $this->fetch('admin.notice/index');
    }

    public function update()
    {
        $post = dcArrayFilter(input('post.'), array_keys($this->formItems()));
        if(!$post){
            $this->error('参数错误');
        }

        $post = array_merge(config('index.'),$post);

        $this->configSave('./config/index.php', $post, 'index/admin.notice/index');
    }
    
    private function formItems($data=[])
    {
        return [
            'notice' => [
                'type'        => 'textarea',
                'value'       => $data['notice'],
                'required'    => false,
                'rows'        => 10,
                'title'       => '支持HTML标签',
                'class_row'   => 'mb-3',
                'class_label' => 'form-label',
            ],
        ];
    }
}